import BaseModel from "../base/model/BaseModel";
// import LangManager from "../lang/LangManager";
import XlsxData from "../config/XlsxData";
import ResLoader from "../res/ResLoader";
import XlsxDataManager from "../config/XlsxDataManager";
import ResItem from "../res/ResItem";
import Resolution from "../tools/Resolution";
import MusicManager from "../audio/MusicManager";
import SoundManager from "../audio/SoundManager";
import AudioManager from "../audio/AudioManager";
import ShakeManager from "../audio/ShakeManager";
export default class GameManager extends BaseModel {

 
    protected resLoader:ResLoader;

    protected dataManager: XlsxDataManager;

    protected gameID:string;

    // protected langManager: LangManager;
    protected musicMgr: MusicManager;
    protected soundMgr: SoundManager;
    constructor(){
        super();
        this.resLoader = new ResLoader();
        // this.langManager = new LangManager();
        this.dataManager = new XlsxDataManager();
        this.musicMgr = new MusicManager(this.getLoader())
        this.soundMgr = new SoundManager(this.getLoader());          
    }
    private static ins: GameManager;

    static instance(): GameManager{
        if(!this.ins){
            this.ins = new GameManager();
        }
        return this.ins;
    }

    init(gameID:string,account:string){
        this.gameID = gameID;
        AudioManager.instance().init(account);
        ShakeManager.instance().init(account)
        Resolution.init();
    }

    setLang(lang:string){
        let langConfig = 'data/game_lang_'+lang
        this.addFile(langConfig)
        // this.langManager.setPath(this.gameID+"pic/font/")
        // this.langManager.setLang(lang,this.dataManager.get(langConfig))        
    }

    playMusic(name:string,isLoop:boolean = true){
        this.musicMgr.play(name,isLoop)
    }

    playSound(name:string){
        this.soundMgr.play(name)
    }
    getLocalString(id,opt?){
        // return this.langManager.getLocalString(id,opt)
    }


    loadRes(file:string,type:typeof cc.Asset,callback:(err,resItem:ResItem)=>void){
        this.resLoader.loadRes(file,type,callback);
    }


    addFile(fileName:string){
        this.dataManager.addFile(fileName,this.resLoader.getRes(fileName,cc.JsonAsset))
    }


    getDataManager():XlsxDataManager{
        return this.dataManager;
    }

    // getLangManager():LangManager{
    //     return this.langManager;
    // }

    getConfig(name:string){
        return this.dataManager.get(name)
    }

    getLoader(){
        return this.resLoader;
    }

    release(){
        this.dataManager.clear();
        this.resLoader.release();
    }


    setGameID(gameID: string){
        this.gameID = gameID;
    }
    getGameID():string{
        return this.gameID;
    }



}
